package org.example.traing.service.Impl;


import org.example.traing.VO.CategoryVO;
import org.example.traing.VO.ClassVO;
import org.example.traing.VO.JobStatusVO;
import org.example.traing.VO.JobVO;
import org.example.traing.entity.JobDetail;
import org.example.traing.entity.UserDetail;
import org.example.traing.entity.UserJob;
import org.example.traing.persistence.JobMapper;
import org.example.traing.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("JobService")
public class JobImpl implements JobService {

    @Autowired
    JobMapper jobMapper;

    public List<ClassVO> getJobClass(){

        return jobMapper.getJobClass();
    }

    @Override
    public List<CategoryVO> getJobCategory() {

        return jobMapper.getJobCategory();
    }

    @Override
    public List<JobDetail> getJob(String category) {
        return jobMapper.getJob(category);
    }

    public JobDetail getJobDetail(String jobId){

        return jobMapper.getJobDetail(jobId);
    }


    public List<JobStatusVO> getJobStatus(String jobId){
        return jobMapper.getJobStatus(jobId);

    }



    @Transactional
    public int addJob(JobDetail jobDetail ,String categoryName){
        String jobId =jobDetail.getJobId();
        int a = jobMapper.addCategoryJob(categoryName,jobId);
        int b = jobMapper.addJob(jobDetail);
        if(a==0||b==0){
            return 0;
        }else{
            return 1;
        }

    }
    public List<JobDetail> getAllJobs(){
        return jobMapper.getAllJobs();
    }

    public List<CategoryVO> getCategoryByClass(String className){

       return jobMapper.getCategoryByClass(className);
    }

    @Transactional
    public JobDetail updateJob(JobDetail jobDetail){
        jobMapper.updateJob(jobDetail);
        return jobMapper.getJobDetail(jobDetail.getJobId());

    }

    public List<JobDetail> getKeyJobs(String keyword){
       return jobMapper.getKeyJobs(keyword);
    }
}
